unit UretimBeklemeNedeni;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons, ExtCtrls, DB, ADODB, Mask, wwdbedit,
  Wwdotdot, Wwdbcomb, wwdbdatetimepicker, cxStyles, cxCustomData,
  cxGraphics, cxFilter, cxData, cxDataStorage, cxEdit, cxDBData,
  cxGridLevel, cxClasses, cxControls, cxGridCustomView,
  cxGridCustomTableView, cxGridTableView, cxGridDBTableView, cxGrid,
  cxImageComboBox, cxGridExportLink, wwdblook;

type
  TUretimBeklemeNedeniF = class(TForm)
    BeklemeNedeniQ: TADOQuery;
    BeklemeNedeniQS: TDataSource;
    Panel1: TPanel;
    Panel2: TPanel;
    blistele: TBitBtn;
    bkapat: TBitBtn;
    Label15: TLabel;
    basTark: TwwDBDateTimePicker;
    BitTark: TwwDBDateTimePicker;
    Label14: TLabel;
    cxGrid1: TcxGrid;
    cxGrid1DBTableView1: TcxGridDBTableView;
    cxGrid1Level1: TcxGridLevel;
    toplamsaatl: TLabel;
    toplamsaatk: TLabel;
    Duruml: TLabel;
    lcBeklemeNeden: TwwDBLookupCombo;
    aqBeklemeNeden: TADOQuery;
    cxGrid1DBTableView1AdSoyad: TcxGridDBColumn;
    cxGrid1DBTableView1Tarih: TcxGridDBColumn;
    cxGrid1DBTableView1bassaat: TcxGridDBColumn;
    cxGrid1DBTableView1bitsaat: TcxGridDBColumn;
    cxGrid1DBTableView1Neden: TcxGridDBColumn;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormShow(Sender: TObject);
    procedure bkapatClick(Sender: TObject);
    procedure FormKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure blisteleClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
    t1, t2, tt: ttime;

  public
    { Public declarations }
  end;

var
  UretimBeklemeNedeniF: TUretimBeklemeNedeniF;

implementation
uses data;
{$R *.dfm}

procedure TUretimBeklemeNedeniF.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  Action := CaFree;
  UretimBeklemeNedeniF := nil;
end;

procedure TUretimBeklemeNedeniF.FormShow(Sender: TObject);
begin
  YerAyarla(Self, False);
  BasTark.date := SadeceTarih;
  BitTark.date := SadeceTarih;
  blistele.click;
end;

procedure TUretimBeklemeNedeniF.bkapatClick(Sender: TObject);
begin
  close;
end;

procedure TUretimBeklemeNedeniF.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if key = vk_f5 then
    blistele.click;
end;

procedure TUretimBeklemeNedeniF.blisteleClick(Sender: TObject);
begin
  BeklemeNedeniQ.close;
  BeklemeNedeniQ.SQL.Text := 'select B.id,AdSoyad=(P.Adi+'' ''+P.Soyadi),B.Tarih,B.bassaat,B.bitsaat,Neden=N.isim ' +
    ' from BeklemeNedeni B ' +
    ' left join Perkart P on (P.Perkod=B.ilgili) ' +
    ' left join TblBeklemeNeden N on (N.id=B.Nedenid) ' +
    ' where 1=1 ';

  if bastark.Text <> '' then
    BeklemeNedeniQ.SQL.Add(' and tarih>=' + #39 + bastark.Text + #39);

  if bittark.Text <> '' then
    BeklemeNedeniQ.SQL.Add(' and tarih<=' + #39 + bittark.Text + #39);

  if lcBeklemeNeden.Text <> '' then
    BeklemeNedeniQ.SQL.Add(' and Nedenid=' + #39 + lcBeklemeNeden.LookupValue + #39);

  BeklemeNedeniQ.open;

  tt := strtotime('00:00:00');
  while not BeklemeNedeniQ.Eof do
  begin
    if not BeklemeNedeniQ.fieldbyname('bassaat').isnull then
      t1 := strtotime(BeklemeNedeniQ.fieldbyname('bassaat').Value);

    if not BeklemeNedeniQ.fieldbyname('bitsaat').isnull then
      t2 := strtotime(BeklemeNedeniQ.fieldbyname('bitsaat').Value);

    if (not BeklemeNedeniQ.fieldbyname('bassaat').isnull) and (not
      BeklemeNedeniQ.fieldbyname('bitsaat').isnull) then
    begin
      tt := tt + t2 - t1;
    end;

    BeklemeNedeniQ.Next;
  end;

  toplamsaatk.caption := timetostr(tt);
end;

procedure TUretimBeklemeNedeniF.FormCreate(Sender: TObject);
begin
  aqBeklemeNeden.Open;
end;

end.

